/*
 * Copyright (c) Huawei Device Co., Ltd. 2023. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef APDU_VALIDATOR_H
#define APDU_VALIDATOR_H

#include <string>

namespace OHOS {
namespace SE {
class ApduValidator final {
public:
    static constexpr size_t CMD_APDU_LENGTH_CASE1 = 4;
    static constexpr size_t CMD_APDU_LENGTH_CASE2 = 5;
    static constexpr size_t CMD_APDU_LENGTH_CASE2_EXTENDED = 7;
    static constexpr size_t CMD_APDU_LENGTH_CASE3_WITHOUT_DATA = 5;
    static constexpr size_t CMD_APDU_LENGTH_CASE3_WITHOUT_DATA_EXTENDED = 7;
    static constexpr size_t CMD_APDU_LENGTH_CASE4_WITHOUT_DATA = 6;
    static constexpr size_t CMD_APDU_LENGTH_CASE4_WITHOUT_DATA_EXTENDED = 9;
    static constexpr uint32_t MAX_EXPECTED_DATA_LENGTH = 65536;

    /**
     * @brief Check the ISO7816 command is valid or not.
     * @param apdu The ISO7816 command.
     */
    static void CheckCommand(const std::string& apdu);

private:
    static void CheckLe(uint32_t le);
    static void CheckCla(size_t cla);
    static void CheckIns(size_t ins);
};
}  // namespace SE
}  // namespace OHOS
#endif // !APDU_VALIDATOR_H